﻿using System;
using System.Linq;
using System.Runtime.Serialization;
using BusinessTier;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BusinessTierTest
{
    [TestClass]
    public class TagShould
    {
        private Tag _tag;
        [TestInitialize]
        public void Setup()
        {
            _tag = new Tag("SomeName");
        }

        [TestMethod]
        public void TagReceivedData()
        {
            var serializableDouble =  new SerializableDouble();
            _tag.TagObject(serializableDouble);
            var taggedObjects = _tag.TaggedObjects.ToArray();
            Assert.AreEqual(1,taggedObjects.Count());
            Assert.AreEqual(true,((SerializableDouble) taggedObjects.ElementAt(0)).IsDeseialized);
        }
    }

    [Serializable]
    public class SerializableDouble : ISerializable
    {
        public string Id { get; set; }
        public bool IsDeseialized { get; set; }

        public SerializableDouble()
        {           
            IsDeseialized = false;
            Id = "SomeId";
        }

        public SerializableDouble(SerializationInfo serializationInfo,StreamingContext streamingContext)
        {
            IsDeseialized = true;
            Id = serializationInfo.GetString("Id");
        }

        public void GetObjectData(SerializationInfo serializationInfo, StreamingContext ctxt)
        {
            serializationInfo.AddValue("Id",Id);
        }
    }
}
